package org.example;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.example.resource.HelloServiceImpl;
import org.example.resource.ServerShutdownImpl;
import org.example.resource.StudentResource;
import org.junit.Test;

public class Server {
	/**
	 * Start the server here,inlcuding  the JAX-WS service and the JAX-RS service
	 * @param args
	 */
	public static void main(String[] args) {
		JAXRSServerFactoryBean factory=new JAXRSServerFactoryBean();
		factory.setAddress("http://localhost:8080/");
		factory.setServiceBean(new StudentResource());
		factory.getInInterceptors().add(new LoggingInInterceptor());
		factory.getOutInterceptors().add(new LoggingOutInterceptor());
		factory.create();
		System.out.println("RS Done");
		
		JaxWsServerFactoryBean factoryWs=new JaxWsServerFactoryBean();
		//设置服务地址
		factoryWs.setAddress("http://localhost:8000/ws/hello");
		//设置服务类
		factoryWs.setServiceBean(new HelloServiceImpl());
		//添加日志输入输出拦截器，观察soap响应、请求情况
		factoryWs.getInInterceptors().add(new LoggingInInterceptor());
		factoryWs.getOutFaultInterceptors().add(new LoggingOutInterceptor());
		//发布服务
		factoryWs.create();
		System.out.println("WS Publish Service Success");
		
//		//Setting the service address
//		JaxWsServerFactoryBean factoryWs2=new JaxWsServerFactoryBean();
//		factoryWs2.setAddress("http://localhost:8000/ws/st");
//		//Setting up a service classes
//		factoryWs2.setServiceBean(new ServerShutdownImpl());
//		//Add log input/output interceptor to watch soap responses, requests
//		factoryWs2.getInInterceptors().add(new LoggingInInterceptor());
//		factoryWs2.getOutFaultInterceptors().add(new LoggingOutInterceptor());
//		//Publish Service
//		factoryWs2.create();
//		System.out.println("WS 发布服务成功");
	}
}
